Add lap start as a waypoint in gtrnctr read.
authorrobertl <robertl>
Sat, 28 Feb 2009 22:29:42 +0000 (22:29 +0000)
committerrobertl <robertl>
Sat, 28 Feb 2009 22:29:42 +0000 (22:29 +0000)
gtrnctr.c

index 84eade8970386d0dffd6da04ba3470b688b0dab4..67f30429e53ccc86c81f85cfd88ee7b42f16a603 100644 (file)
--- a/gtrnctr.c
+++ b/gtrnctr.c
@@ -23,6 +23,8 @@
 #include "xmlgeneric.h"
 
 static gbfile *ofd;
+static int lap_ct = 0;
+static int lap_s = 0;
 static waypoint *wpt_tmp;
 static route_head *trk_head;
 static computed_trkdata *tdata;
@@ -70,6 +72,7 @@ gtc_read(void)
 /* Tracks */
 static xg_callback     gtc_trk_s;
 static xg_callback     gtc_trk_ident;
+static xg_callback     gtc_trk_lap_s, gtc_trk_lap_e;
 static xg_callback     gtc_trk_pnt_s, gtc_trk_pnt_e;
 static xg_callback     gtc_trk_utc;
 static xg_callback     gtc_trk_lat;
@@ -98,6 +101,8 @@ static xg_tag_mapping gtc_map[] = {
        /* history tcx v2 (activities) */
        { gtc_trk_s,    cb_start, "/Activities/Activity" },
        { gtc_trk_ident,cb_cdata, "/Activities/Activity/Id" },
+       { gtc_trk_lap_s,cb_start, "/Activities/Activity/Lap" },
+       { gtc_trk_lap_e,cb_end,   "/Activities/Activity/Lap" },
        { gtc_trk_pnt_s,cb_start, "/Activities/Activity/Lap/Track/Trackpoint" },
        { gtc_trk_pnt_e,cb_end,   "/Activities/Activity/Lap/Track/Trackpoint" },
        { gtc_trk_utc,  cb_cdata, "/Activities/Activity/Lap/Track/Trackpoint/Time" },
@@ -110,14 +115,16 @@ static xg_tag_mapping gtc_map[] = {
        /* history tcx v1 */
        { gtc_trk_s,    cb_start, "/History/Run" },
        { gtc_trk_ident,cb_cdata, "/History/Run/Id" },
-       { gtc_trk_pnt_s,cb_start, "/History/Run/Track/Trackpoint" },
-       { gtc_trk_pnt_e,cb_end,   "/History/Run/Track/Trackpoint" },
-       { gtc_trk_utc,  cb_cdata, "/History/Run/Track/Trackpoint/Time" },
-       { gtc_trk_lat,  cb_cdata, "/History/Run/Track/Trackpoint/Position/LatitudeDegrees" },
-       { gtc_trk_long, cb_cdata, "/History/Run/Track/Trackpoint/Position/LongitudeDegrees" },
-       { gtc_trk_alt,  cb_cdata, "/History/Run/Track/Trackpoint/AltitudeMeters" },
-       { gtc_trk_hr,   cb_cdata, "/History/Run/Track/Trackpoint/HeartRateBpm" },
-       { gtc_trk_cad,  cb_cdata, "/History/Run/Track/Trackpoint/Cadence" },
+       { gtc_trk_lap_s,cb_start, "/History/Run/Lap" },
+       { gtc_trk_lap_e,cb_end,   "/History/Run/Lap" },
+       { gtc_trk_pnt_s,cb_start, "/History/Run/Lap/Track/Trackpoint" },
+       { gtc_trk_pnt_e,cb_end,   "/History/Run/Lap/Track/Trackpoint" },
+       { gtc_trk_utc,  cb_cdata, "/History/Run/Lap/Track/Trackpoint/Time" },
+       { gtc_trk_lat,  cb_cdata, "/History/Run/Lap/Track/Trackpoint/Position/LatitudeDegrees" },
+       { gtc_trk_long, cb_cdata, "/History/Run/Lap/Track/Trackpoint/Position/LongitudeDegrees" },
+       { gtc_trk_alt,  cb_cdata, "/History/Run/Lap/Track/Trackpoint/AltitudeMeters" },
+       { gtc_trk_hr,   cb_cdata, "/History/Run/Lap/Track/Trackpoint/HeartRateBpm" },
+       { gtc_trk_cad,  cb_cdata, "/History/Run/Lap/Track/Trackpoint/Cadence" },
 
        { gtc_wpt_pnt_s,cb_start, "/Courses/Course/Lap/BeginPosition" },
        { gtc_wpt_pnt_e,cb_end, "/Courses/Course/Lap/BeginPosition" },
@@ -411,6 +418,19 @@ gtc_trk_ident(const char *args, const char **unused)
        trk_head->rte_name = xstrdup(args);
 }
 
+void
+gtc_trk_lap_s(const char *unused, const char **attrv)
+{
+       lap_ct++;
+       lap_s = 1;
+}
+
+void
+gtc_trk_lap_e(const char *unused, const char **attrv)
+{
+       lap_s = 0;
+}
+
 void
 gtc_trk_pnt_s(const char *unused, const char **attrv)
 {
@@ -420,10 +440,23 @@ gtc_trk_pnt_s(const char *unused, const char **attrv)
 void
 gtc_trk_pnt_e(const char *args, const char **unused)
 {
-        if(wpt_tmp->longitude != 0. && wpt_tmp->latitude != 0.) track_add_wpt(trk_head, wpt_tmp);
+        if(wpt_tmp->longitude != 0. && wpt_tmp->latitude != 0.) {
+               if (lap_s) {
+                       /* Add the first point of an ActivityLap as
+                       a waypoint as well as a trackpoint. */
+                       char cbuf[10];
+                       waypoint* wpt_lap_s = waypt_dupe(wpt_tmp);
+                       snprintf(cbuf, sizeof(cbuf), "LAP%03d", lap_ct);
+                       wpt_lap_s->shortname = xstrdup(cbuf);
+                       waypt_add(wpt_lap_s);
+               }
+
+               track_add_wpt(trk_head, wpt_tmp);
+       }
        else waypt_free(wpt_tmp);
 
        wpt_tmp = NULL;
+       lap_s = 0;
 }
 
 void